package service

import (
	model "antiquity_map/internal/models"
	repository "antiquity_map/internal/repositories"
	"strconv"
	"time"

	"github.com/google/uuid"
)

type DataService interface {
	GetAllRecords(locationID, page, pageSize string) ([]model.SingleRecord, int64, error)
	GetRecordID(locationID, userID string) error
}

type dataService struct {
	dataRepo repository.DataRepository
}

func NewDataService(dataRepo repository.DataRepository) DataService {
	return &dataService{
		dataRepo: dataRepo,
	}
}

func (d *dataService) GetAllRecords(locationID, page, pageSize string) ([]model.SingleRecord, int64, error) {
	records, total, err := d.dataRepo.GetAllRecords(locationID, page, pageSize)
	return records, total, err
}
func (d *dataService) GetRecordID(locationID, userID string) error {
	currentTime := strconv.FormatInt(time.Now().Unix(), 10)
	uuid := uuid.Must(uuid.NewV7())
	collectionID := uuid.String()
	err := d.dataRepo.GetRecordID(locationID, userID, collectionID, currentTime)
	return err
}
